package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.IUserFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户关注操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/user")
public class UserFollowController extends BaseController
{
    @Autowired
    private IUserFollowService userFollowService;

    /**
     * 关注/取消关注用户
     */
    @PostMapping("/follow/{followedUserId}")
    public AjaxResult toggleFollow(@PathVariable Long followedUserId)
    {
        Long userId = SecurityUtils.getUserId();
        if (userId.equals(followedUserId))
        {
            return AjaxResult.error("不能关注自己");
        }
        boolean isFollowed = userFollowService.toggleFollow(userId, followedUserId);
        return AjaxResult.success(isFollowed ? "关注成功" : "已取消关注", isFollowed);
    }
    
    /**
     * 检查是否已关注用户
     */
    @GetMapping("/follow/check/{followedUserId}")
    public AjaxResult checkFollow(@PathVariable Long followedUserId)
    {
        Long userId = SecurityUtils.getUserId();
        boolean isFollowed = userFollowService.checkUserFollowed(userId, followedUserId);
        return AjaxResult.success(isFollowed);
    }

    /**
     * 获取当前用户关注的用户列表
     */
    @GetMapping("/follows")
    public AjaxResult getMyFollows() {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(userFollowService.selectFollowsByUserId(userId));
    }

    /**
     * 获取当前用户的粉丝列表
     */
    @GetMapping("/fans")
    public AjaxResult getMyFans() {
        Long userId = SecurityUtils.getUserId();
        return AjaxResult.success(userFollowService.selectFansByUserId(userId));
    }
} 